package edu.pitt.dbmi.odie.gapp.gwt.client.analysis;

import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Progressbar;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

import edu.pitt.dbmi.odie.gapp.gwt.client.dao.ODIE_DaoAnalysis;

public class ODIE_ProgressDisplay extends VLayout {

	private final int barWidth = 500 ;
	
	private final int barHeight = 14 ;
	
	private final String barColor = "#E7FFDF" ;
	
	private final Label hBar1Label = new Label("Directory Progress");
	private final Progressbar hBar1 = new Progressbar() ;
	
	private final Label hBar2Label = new Label("Current File Progress");
	private final Progressbar hBar2 = new Progressbar() ;
	
	private int hBar1Value;
	private int hBar2Value;

	public ODIE_ProgressDisplay() {
		
		setIsGroup(true);
		setGroupTitle("Annotation Progress");
		
		
		
		HLayout horizontalDocumentBars = new HLayout(2);
		horizontalDocumentBars.setLayoutMargin(10) ;
		horizontalDocumentBars.setMembersMargin(5) ;
		horizontalDocumentBars.setWidth100() ;
		
		HLayout horizontalSentenceBars = new HLayout(2);
		horizontalSentenceBars.setLayoutMargin(10) ;
		horizontalSentenceBars.setMembersMargin(5) ;
		horizontalSentenceBars.setWidth100() ;

		hBar1Label.setHeight(16);
		horizontalDocumentBars.addMember(hBar1Label);

//		hBar1.setWidth(barWidth) ;
		hBar1.setWidth("*") ;
		hBar1.setHeight(14) ;
		hBar1.setVertical(false);
		horizontalDocumentBars.addMember(hBar1);

		hBar2Label.setHeight(16);
		horizontalSentenceBars.addMember(hBar2Label);

//		hBar2.setWidth(barWidth) ;
		hBar2.setWidth("*") ;
		hBar2.setHeight(14) ;
		hBar2.setVertical(false);
		horizontalSentenceBars.addMember(hBar2);

		hBar1Value = 0;
		hBar2Value = 0;
		hBar1.setPercentDone(hBar1Value);
		hBar1Label.setContents("Document Status");
		hBar2.setPercentDone(hBar2Value);
		hBar2Label.setContents("Sentence Status");
		
		VLayout verticalDocumentAndSentenceBars = new VLayout() ;
		verticalDocumentAndSentenceBars.setLayoutMargin(5) ;
		verticalDocumentAndSentenceBars.setMembersMargin(5) ;
		verticalDocumentAndSentenceBars.setWidth100() ;
		
		addMember(horizontalDocumentBars) ;
		addMember(horizontalSentenceBars) ;

		draw();
	}

	public void progress(ODIE_DaoAnalysis result) {

		float unitsCompleted = result.getUnitsCompleted() ;
		float unitsRequested = result.getUnitsRequested() ;
		hBar1Value = Math.round(100.0f * (unitsCompleted  / unitsRequested));
		
		float subUnitsCompleted = (result.getSubUnitsCompleted() == null) ? 0.0f :  result.getSubUnitsCompleted();
		float subUnitsRequested = (result.getSubUnitsRequested() == null) ? 1.0f :  result.getSubUnitsRequested();
		hBar2Value = Math.round(100.0f * (subUnitsCompleted  / subUnitsRequested));
		
		hBar1.setPercentDone(hBar1Value);
		hBar1Label.setContents(result.getProcessingUnitName());
		hBar2.setPercentDone(hBar2Value);
		hBar2Label.setContents(result.getProcessingSubUnitName());

		redraw();
	}

	public void reset() {
		hBar1Value = 0;
		hBar2Value = 0;
		hBar1.setPercentDone(hBar1Value);
		hBar1Label.setContents("Document Status");
		hBar2.setPercentDone(hBar2Value);
		hBar2Label.setContents("Sentence Status");
		redraw() ;
	
	}

}
